
//	afxpropertygridctrl.cpp is original
typedef CMFCPropertyGridProperty	CProPro;

class CDVKProGridCtrl : public CMFCPropertyGridCtrl
{
public:
 static CProPro * DeleteProperty(CMFCPropertyGridCtrl * pCtrl, CProPro * pPro)
	{
		CRect therect = pCtrl->GetListRect();
		CProPro * pOwner = pPro->GetParent();
		if (pOwner)	
		{
			POINT thepoint = (pOwner->GetRect()).CenterPoint();
			if (!(therect.PtInRect(thepoint)))
				pCtrl->EnsureVisible(pOwner);
			pCtrl->SetCurSel(pOwner);
			pOwner->Expand(FALSE);
			return pOwner;
		}
	//	CRect GetListRect() const { return m_rectList; }
		POINT thepoint = (pPro->GetRect()).CenterPoint();
		if (!(therect.PtInRect(thepoint)))
		{
			pCtrl->EnsureVisible(pPro);
			return pPro;
		}

		pCtrl->DeleteProperty(pPro);
			pPro = pCtrl->HitTest(thepoint);
		if (!pPro && pCtrl->GetPropertyCount())
		{
			int index = pCtrl->GetPropertyCount() - 1;
				pPro = pCtrl->GetProperty(index);
			if (!(pPro->IsVisible())) pPro = NULL;
		}
	//	CRect GetRect() const { return m_Rect; }
		pCtrl->SetCurSel(pPro);
		return pPro;
	}

	CDVKProGridCtrl() { m_bDescriptionArea = TRUE; m_bHeaderCtrl = FALSE; }
	virtual BOOL Create(DWORD dwStyle, const RECT& arect, CWnd* pParentWnd, UINT nID)
	{
		BOOL retval = CMFCPropertyGridCtrl::Create(dwStyle, arect, pParentWnd, nID);
		if (!retval) return retval;
//		EnableHeaderCtrl(FALSE); AdjustLayout();

		m_clrBackground = ::GetSysColor(COLOR_BTNFACE);
	//	m_brBackground.DeleteObject();
		m_brBackground.CreateSolidBrush(m_clrBackground);

		return retval;
	}

	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		if ((pMsg->message == WM_KEYDOWN) && m_pSel)
		if ((pMsg->wParam == VK_SHIFT)	|| 
			(pMsg->wParam == VK_TAB)	||
			(pMsg->wParam == VK_CONTROL))
			// stop below processing, if edit but it is disallowed 
			if (m_pSel->IsInPlaceEditing()) 
				return FALSE;	
				//	m_pSel->IsAllowEdit()

		return CMFCPropertyGridCtrl::PreTranslateMessage(pMsg);
	}

	virtual ~CDVKProGridCtrl() {};
};

class CDVKPropertyGridProperty : public CMFCPropertyGridProperty
{
private:	// Attributes
	CBrush m_brBackground;

/*	virtual BOOL PushChar(UINT nChar)
	{
		if (!m_bAllowEdit && m_bInPlaceEdit && m_bEnabled)
		if ((nChar == VK_SHIFT) || 
//			(nChar == VK_TAB) ||
			(nChar == VK_CONTROL))
				return FALSE;
		// stop below processing, if edit but it is disallowed 
		*/

public:	// Construction

	CDVKPropertyGridProperty(LPCWSTR aname, const VARIANT & avar, LPCWSTR adesc = NULL) : 
		CMFCPropertyGridProperty(aname, avar, adesc) 
		{
			m_bAllowEdit = FALSE;
			if ((VT_I1 < avar.vt) && (avar.vt < VT_UINT))
				if ((avar.ulVal) >> 10)	// size
				{
					m_varValue.ulVal = avar.ulVal / 1024;
					m_strFormatULong = L"%u KB";
				}
					else m_strFormatULong = L"%u bytes";
		}

	CDVKPropertyGridProperty(LPCWSTR anattr, 
			const COleVariant& varValue, 
			LPCWSTR adesc, 
			DWORD_PTR dwData) : 
		CMFCPropertyGridProperty(anattr, varValue, adesc, dwData) 
		{ 
			m_brBackground.CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
		}

	virtual HBRUSH OnCtlColor(CDC* pDC, UINT nCtlColor)
	{
		if (IsAllowEdit())
			if (IsModified() || m_bInPlaceEdit)
		{	//	COLORREF theclr = ;
			pDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
			return (HBRUSH) m_brBackground.GetSafeHandle();
		}
		
		return CMFCPropertyGridProperty::OnCtlColor(pDC, nCtlColor);
	}

	virtual void OnDrawValue(CDC* pDC, CRect arect)
	{
		if (IsModified())
		{
			COLORREF  theclr = ::GetSysColor(COLOR_WINDOW);
			CBrush brBackground;
				brBackground.CreateSolidBrush(theclr);
			RECT therect = arect;
				::InflateRect(& therect, 2, 2);
			pDC->FillRect(& therect, & brBackground);
		}
		CMFCPropertyGridProperty::OnDrawValue(pDC, arect);
	}

	virtual void OnDrawDescription(CDC* pDC, CRect arect)
	{
		if (m_strDescr.IsEmpty()) return;

		CString thedesc = m_strDescr;
				thedesc.Trim(L"[]");

		int nHeight = pDC->DrawText(m_strName, arect, DT_SINGLELINE | DT_NOPREFIX);
			arect.top += nHeight + 2;

		if (thedesc.IsEmpty())
		{
			if (IsModified()) thedesc = L" = ";
		}
			else thedesc = m_strDescr;

		CFont *	pFont = & (m_pWndList->GetBoldFont());
		HFONT hOldFont = (HFONT) ::SelectObject(pDC->GetSafeHdc(), pFont->GetSafeHandle());
		if (thedesc.GetLength())
		{
			nHeight = pDC->DrawText(thedesc, arect, DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS);
			arect.top += nHeight + 2;
		}
		::SelectObject(pDC->GetSafeHdc(), hOldFont);

		if (IsModified())
		{
			CString thestr = m_varValueOrig;
			if (thestr.GetLength())
			pDC->DrawText(thestr, arect, DT_SINGLELINE | DT_NOPREFIX);
		}

		return;
	}

};
